function fv=range1(r0,a,b,x,xlimit,v,dmy)
%**************************************************************
%** This is a supporting function for LSxtreg.m              **
%** Created by Min-Hua Huang, Jan 25, 2012                   **
%** r0: parameter estimates                                  **
%** a: lower bound                                           **
%** b: upper bound                                           **
%** x: independent variable matrix                           **
%** xlimit: maximim and minimum of the independent variables **
%** v: indicator variables                                   **
%** dmy: number of dummy variables                           **
%** output: least and greatest predicted values              **
%**************************************************************
m=size(x,2)-1; g=ones(m+2,2); m1=m+1-dmy; 
%maxty2=max((y2-mean(y2))/std(y2));
%minty2=min((y2-mean(y2))/std(y2));
%distmax=mean(y2)+maxty2*frac*std(y2);
%distmin=mean(y2)+minty2*frac*std(y2);
%maximum and minimum of dummnies
dmymax=max(r0(m1+1:m+1));
dmymin=min(r0(m1+1:m+1));
%maximum and minimum vectors of estimated y when xj is held at its min.
ynonj=ones(m+1,2)*-999;
ynonj(1,1)=(v(2:m1,1).*r0(2:m1))'*xlimit(2:m1,1)+dmymax+b;
ynonj(1,2)=(v(2:m1,2).*r0(2:m1))'*xlimit(2:m1,1)+dmymin+a;
for i=2:1:m1
    ynonj(i,1)=(v(1:m1,1).*r0(1:m1))'*xlimit(1:m1,1)-v(i,1)*r0(i)*xlimit(i,1)+dmymax+b;%+distmax;
    ynonj(i,2)=(v(1:m1,2).*r0(1:m1))'*xlimit(1:m1,1)-v(i,2)*r0(i)*xlimit(i,1)+dmymin+a;%+distmin;
end
ynonj(m1+1:m+1,1)=(v(1:m1,1).*r0(1:m1))'*xlimit(1:m1,1)+b; %+distmax;
ynonj(m1+1:m+1,2)=(v(1:m1,2).*r0(1:m1))'*xlimit(1:m1,1)+a; %+distmin;
%constraints vector
g(1,2)=r0(1)+ynonj(1,1);
g(1,1)=ynonj(1,2)+r0(1);
g(2,2)=r0(1)+b;
g(2,1)=r0(1)+a;
for i=1:1:m
    g(i+2,2)=ynonj(i+1,1)+r0(i+1)*xlimit(i+1,1);
    g(i+2,1)=ynonj(i+1,2)+r0(i+1)*xlimit(i+1,1);
end
fv=g;     